package com.huige.controller;

import com.huige.pojo.Headline;
import com.huige.service.HeadlineService;
import com.huige.utils.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yaml.snakeyaml.events.Event;

/**
 * @Author 朱志辉
 * @Create 2024/7/24 下午5:34
 * @Version 1.0
 * Description:
 */
@RestController
@RequestMapping("headline")
@CrossOrigin
public class HeadlineController {

    @Autowired
    private HeadlineService headlineService;


    /**
     * 发布头条
     * @param headline
     * @param token
     * @return
     */
    @PostMapping("publish")
    public Result publish(@RequestBody Headline headline,@RequestHeader String token) {
        Result result = headlineService.publish(headline,token);
        return result;
    }

    /**
     * 头条回显
     * @param hid
     * @return
     */
    @PostMapping("findHeadlineByHid")
    public Result findHeadlineByHid(Integer hid) {
        Result result = headlineService.findHeadlineByHid(hid);
        return result;
    }

    /**
     * 头条修改实现
     * @param headline
     * @return
     */
    @PostMapping("update")
    public Result updateById(@RequestBody Headline headline) {
        headlineService.updateById(headline);
        return Result.ok(null);
    }


    /**
     * 删除头条
     * @param hid
     * @return
     */
    @PostMapping("removeByHid")
    public Result removeById(Integer hid){
        headlineService.removeById(hid);
        return Result.ok(null);
    }



}
